package com.jerp.ui.main;

import java.util.ArrayList;
import java.util.List;

import com.jerp.ui.auth.IAuthorized;
import com.jerp.ui.auth.UserCredential;

public class SideBarManager {

	private List<MenuItem> menuBar;
	private UserCredential usrCred;

	public UserCredential getUsrCred() {
		if (usrCred == null) {
			usrCred = UserUIManager.getCurrentUser();
		}
		return usrCred;
	}

	public List<MenuItem> getMenuBar() {
		if (menuBar == null) {
			menuBar = createMenubar();
		}
		return menuBar;
	}

	private List<MenuItem> createMenubar() {
		List<MenuItem> menuBar = new ArrayList<MenuItem>();
		MenuItem item, child = null;
		for (int i = 1; i <= 10; i++) {
			item = new MenuItem("Menu " + i, "Role" + IAuthorized.SEPERATOR + i);
			if (i % 2 == 0) {
				for (int j = 1; j < 6; j++) {
					child = new MenuItem("Menu " + i + "-" + j, "Role"
							+ IAuthorized.SEPERATOR + i + IAuthorized.SEPERATOR
							+ j);
					item.addChild(child);
				}
			}
			menuBar.add(item);
		}
		return menuBar;
	}

	public void setMenuBar(List<MenuItem> menuBar) {
		this.menuBar = menuBar;
	}

}
